#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
#include<map>
using namespace std;
string s;
map<string, string> mp;

void init()
{
	mp["imasu"] = "tte"; mp["chimasu"] = "tte"; mp["rimasu"] = "tte";
	mp["mimasu"] = "nde"; mp["bimasu"] = "nde"; mp["nimasu"] = "nde";
	mp["kimasu"] = "ite";
	mp["gimasu"] = "ide";
	mp["shimasu"] = "shite";
}

int main()
{
	init();
	int t;
	cin >> t;
	while (t--)
	{
		cin >> s;
		if (s == "ikimasu")
		{
			cout << "itte" << endl;
			continue;
		}
		int n = s.size();
		if (n >= 7 && mp.find(s.substr(n - 7, 7)) != mp.end())
			cout << s.substr(0, n - 7) << mp[s.substr(n - 7, 7)] << endl;
		else if (n >= 6 && mp.find(s.substr(n - 6, 6)) != mp.end())
			cout << s.substr(0, n - 6) << mp[s.substr(n - 6, 6)] << endl;
		else if (n >= 5 && mp.find(s.substr(n - 5, 5)) != mp.end())
			cout << s.substr(0, n - 5) << mp[s.substr(n - 5, 5)] << endl;
		else
			cout << s << endl;
	}
	return 0;
}
